package com.ruoyi.web.controller.youxuan;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.YouxuanUser;
import com.ruoyi.system.service.IYouxuanUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户管理Controller
 * 
 * @author admin
 * @date 2021-01-07
 */
@RestController
@RequestMapping("/youxuan/user")
public class YouxuanUserController extends BaseController
{
    @Autowired
    private IYouxuanUserService youxuanUserService;

    /**
     * 查询用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('youxuan:user:list')")
    @GetMapping("/list")
    public TableDataInfo list(YouxuanUser youxuanUser)
    {
        startPage();
        List<YouxuanUser> list = youxuanUserService.selectYouxuanUserList(youxuanUser);
        return getDataTable(list);
    }

    /**
     * 导出用户管理列表
     */
    @PreAuthorize("@ss.hasPermi('youxuan:user:export')")
    @Log(title = "用户管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(YouxuanUser youxuanUser)
    {
        List<YouxuanUser> list = youxuanUserService.selectYouxuanUserList(youxuanUser);
        ExcelUtil<YouxuanUser> util = new ExcelUtil<YouxuanUser>(YouxuanUser.class);
        return util.exportExcel(list, "user");
    }

    /**
     * 获取用户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('youxuan:user:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(youxuanUserService.selectYouxuanUserById(id));
    }

    /**
     * 新增用户管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:user:add')")
    @Log(title = "用户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YouxuanUser youxuanUser)
    {
        return toAjax(youxuanUserService.insertYouxuanUser(youxuanUser));
    }

    /**
     * 修改用户管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:user:edit')")
    @Log(title = "用户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YouxuanUser youxuanUser)
    {
        return toAjax(youxuanUserService.updateYouxuanUser(youxuanUser));
    }

    /**
     * 删除用户管理
     */
    @PreAuthorize("@ss.hasPermi('youxuan:user:remove')")
    @Log(title = "用户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(youxuanUserService.deleteYouxuanUserByIds(ids));
    }
}
